const vscode = require('vscode');
const path = require('path');
const request = require('./http/request');
const SettingHandler = require('./util/settingHandler');

const hiSmartLiteEx = {
  context: {},
  extensionPath: '',
  language: vscode.env.language,
  childStaticExtensions: [],
  childCommand: [],
  registerCommands: [],
  localResourceRoots: [],
  giteeServiceCli: null,
  oldGiteeServiceCli: null,
  scope: 'projects pull_requests issues notes user_info enterprise_info',
  async initHiSmartLiteEx(context) {
    this.context = context;
    this.extensionPath = this.context.extensionPath;
    this.localResourceRoots.push(vscode.Uri.file(path.join(this.extensionPath, 'media')));
    await this.initConfigClient();
  },

  async initConfigClient() {
    try {
      await initCli();
    } catch (error) {
      console.error('initCli fail, reason:', error);
    }
  }
};

async function initCli() {
  const setting = new SettingHandler();
  // init gitee service
  const giteeServiceUrl = await setting.getGiteeServiceUrl();
  hiSmartLiteEx.giteeServiceCli = await request.initGiteeCli(giteeServiceUrl);
  const oldGiteeUrl = await setting.getServiceUrl();
  hiSmartLiteEx.oldGiteeServiceCli = await request.initGiteeCli(oldGiteeUrl);
}

module.exports = hiSmartLiteEx;